package com.javaee.ch13.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javaee.ch13.entity.BookCopy;
import com.javaee.ch13.web.dto.queryDto.BookCopyQueryDto;
import com.javaee.ch13.web.vo.BookCopyVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 图书副本表 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-05-05
 */
@Mapper
public interface BookCopyMapper extends BaseMapper<BookCopy> {

    Page<BookCopyVo> pageQuery();

    @Select("  SELECT c.*, b.title AS bookName, b.isbn AS bookIsbn, r.name AS borrower\n" +
            "        FROM book_copy c\n" +
            "        LEFT JOIN book b ON c.book_id = b.book_id\n" +
            "        LEFT JOIN borrow_record br ON c.copy_id = br.copy_id\n" +
            "        LEFT JOIN reader r ON br.reader_id = r.reader_id ${ew.customSqlSegment}")
    Page<BookCopyVo> pageQuery_1(@Param("page") Page page,  @Param("ew") QueryWrapper wrapper);


    Page<BookCopyVo> pageQuery(@Param("page") Page page, @Param("query") BookCopyQueryDto queryDto);

}
